package com.zsd.android.opencvface.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<BaseRecyclerAdapter.BaseViewHolder> {

    protected Context mContext;
    protected ArrayList<T> list;
    protected LayoutInflater inflater;

    public BaseRecyclerAdapter(Context mContext, ArrayList<T> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return createHolder(viewGroup, i);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder baseViewHolder, int i) {
        bindHolder(baseViewHolder, i);
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    public abstract BaseViewHolder createHolder(@NonNull ViewGroup viewGroup, int viewType);

    public abstract void bindHolder(@NonNull BaseViewHolder baseViewHolder, int position);

    public static class BaseViewHolder extends RecyclerView.ViewHolder {

        public BaseViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
